# -*- coding: utf-8 -*-


import os
import uuid
import django
from datetime import datetime
from core.initialize import Initialize
from apps.sys.models import Menu, DictType, DictData

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "application.settings")
django.setup()


class Init(Initialize):

    def init_dict(self):
        dict_type = []
        dict_data = []
        self.save(DictType, dict_type, "字典类型")
        self.save(DictData, dict_data, "字典数据")

    def init_menu(self):
        """
        初始化菜单表-工具管理
        """
        tools = uuid.uuid4()
        self.menu_oms_data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": tools,
                "name": "工具管理",
                "type": "M",
                "icon": "tools",
                "path": "/tools",
                "component": "Layout",
                "perms": None,
                "nesting": True,
                "redirect": "noRedirect",
                "parent_id": None,
                "sort": 999,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "常用工具",
                "type": "C",
                "icon": "general",
                "path": "general",
                "component": "tools/general/index",
                "perms": "tools:general:list",
                "parent_id": tools,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "正则工具",
                "type": "C",
                "icon": "regexp",
                "path": "regexp",
                "component": "tools/regexp/index",
                "perms": "tools:regexp:list",
                "parent_id": tools,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "文本比对",
                "type": "C",
                "icon": "textdiff",
                "path": "textdiff",
                "component": "tools/textdiff/index",
                "perms": "tools:textdiff:list",
                "parent_id": tools,
                "sort": 3,
            },
        ]
        self.save(Menu, self.menu_oms_data, "菜单表")

    def run(self):
        self.init_dict()
        self.init_menu()


def main(reset=False):
    Init(reset).run()
    pass


if __name__ == "__main__":
    main()
